/**
*
* @file utils.h
*
* @brief misc utility functions
*
* Copyright ?2011 HID Corporation.  All rights reserved.
*
* This software is protected by copyright law and international treaties.
* Any unauthorized reproduction, distribution or use of the software is prohibited.
*
*/

#ifndef _utils_h
#define _utils_h

#include "stdint.h"

#define ROUND_UP_N(N,VAL,TYPE)              ((TYPE)(((TYPE)(VAL) + (TYPE)((N)-1)) & (TYPE)(~(((TYPE)N)-1))))
#define ROUND_UP_2(VAL,TYPE)                ROUND_UP_N(2,VAL,TYPE)
#define ROUND_UP_4(VAL,TYPE)                ROUND_UP_N(4,VAL,TYPE)
#define ROUND_UP_8(VAL,TYPE)                ROUND_UP_N(8,VAL,TYPE)

extern void utils_xor_buf(uint8_t* inOutBuff, uint8_t* buff, uint16_t length);
extern void utils_xor(uint8_t* inoutBuff, uint8_t* buff2, uint16_t length);
extern void utils_copy(uint8_t* src, uint8_t* dst, uint16_t length);
extern void utils_fill(uint8_t* dst, uint16_t length, uint8_t pattern);
//extern uint8_t utils_compare(uint8_t* array1, uint8_t* array2, uint16_t length);
//extern uint8_t utils_compare2(uint8_t* array1, uint16_t array1Length, uint8_t* array2, uint16_t array2Length);

extern uint16_t utils_getU2(uint8_t* buffer);
extern uint32_t utils_getU4(uint8_t* buffer);
extern void utils_setU2(uint8_t* buffer, uint16_t value);
extern void utils_setU4(uint8_t* buffer, uint32_t value);
//extern uint16_t utils_msbIndex(uint8_t* buffer, uint16_t bufferLength);

/*
#ifdef LITTLE_ENDIAN
    extern uint32_t swapbytes_u4(uint32_t val);
#else
    #define swapbytes_u4(X)
#endif
*/
#endif
